;$(window).ready(function(){
	if(!App){
		App ? null : {};
		App.pageCustomEnable = false;
		App.pageId = "";
		App.pageCustomCalculateCount = 0;
	}
	
	if(App.pageCustomEnable && App.pageId){
		var $pageCustomData;
		$.ajax({
			type : "POST",
			async : false,
			dataTypeString:"xml",
			url: App.ctx+"/pagecustom.do?pageId="+App.pageId,
			success: reviseAreaControl,
			error : function(xml, str, e) {
				alert('error:' + str + ',' + e);
			}
		});
	}
	function reviseAreaControl(xmlData){
		var xmlDoc = $.parseXML(xmlData);
		$pageCustomData = $(xmlDoc);
		
		$areas = $pageCustomData.find("area");
		$areas.each(function(a_index,a_elm){
			
			if($("ul[id='"+$(a_elm).attr("id")+"']").attr("allowChange")=="true"){
				$widgets = $(a_elm).find("widget");
				
				$widgets.each(function(w_index,w_e){
					//alert(" parentId : "+$(a_elm).attr("id")+"\n id : "+$(w_e).attr("id")+"\n customIndex : "+$(w_e).attr("customIndex")+"\n visible : "+$(w_e).attr("visible"))
					var w_id = $(w_e).attr("id");
					$("#"+w_id).attr('parentId',$(a_elm).attr("id"));
					$("#"+w_id).attr('customIndex',$(w_e).attr("customIndex"));
					$("#"+w_id).attr('visible',$(w_e).attr("visible"));
				})
				
				$widgets.each(function(w_index,w_e){
					var c_id = $(w_e).attr("id");
					var customIndex = $("#"+c_id).attr("customIndex");
					var parentId = $("#"+c_id).attr("parentId")
					var visible = $("#"+c_id).attr("visible")
					
					var hidden = false;
									
					if(customIndex > 1){
						var preElmIndex = customIndex*1-1;
						$("#"+c_id).parent().insertAfter($("[customIndex='"+preElmIndex+"'][parentId='"+parentId+"']").parent());
					}else{
						$("#"+c_id).parent().prependTo($("#"+c_id).parent().parent());
					}
					if(visible==0){
						hidden = true;
					}
					if(hidden){
						$("#"+c_id).parent().hide();
					}
				});
			}
		})
	}
});